<?php

namespace common\observer;

use common\model\TaskModel;
use common\model\UserModel;
use common\service\OptionsService;
use common\service\TaskAssembleService;
use common\service\TaskService;
use common\service\TaskUpstreamService;
use support\SingletonTrait;
use common\model\EntityModel;
use think\Hook;
use Webman\Stomp\Client;
use teamones\dbeventObserver\interfaces\SplSubject;
use teamones\dbeventObserver\interfaces\SplObserver;

/**
 * 任务分执行人发生变化 推送任务上游完成情况
 */
class TaskExecutorChangeNotifyUpstreamDoneStatus implements SplObserver
{
    use SingletonTrait;

    /**
     * @inheritDoc
     */
    function update(SplSubject $subject): void
    {
        $updateData = $subject->getSplUpdateData();
        if (!isset($updateData['executor']) || $updateData['executor'] <= 0) {
            return;
        }
        $task = $subject->getSubjectData();

        $executor = model(UserModel::class)->find($updateData['executor']);
        if (empty($executor)) {
            return;
        }
        $hookData = [
            'type' => 'task_assign',
            'data' => [
                'task' => $task,
                'executor' => $executor,
            ],
        ];
        Hook::listen('task_assign', $hookData);
    }

}
